package mis.ds.ps.ui;

import java.awt.BorderLayout;
import java.awt.CardLayout;
import java.awt.Container;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.*;
import javax.swing.border.EmptyBorder;

/**
*
* @author edjesus
*/
public class ImportForm extends JInternalFrame implements ActionListener {
	private static final long serialVersionUID = 1L;	
	final static String STEP1 = "Step1";
    final static String STEP2 = "Step2";
	
	private JButton btnBack;
    private JButton btnNext;
    private JButton btnCancel;
    
    private JPanel panelCards;
    private JPanel panelStep1;
    private JPanel panelStep2;
    private CardLayout cardLayout;
	
	public ImportForm() {
		super("Carga horária", 
	              true, //resizable
	              true, //closable
	              true, //maximizable
	              true);//iconifiable
		
//		setTitle("TimeTable :: Import");
//		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//		pack();
		setSize(800, 600);
		initComponents();
		
		cardLayout = (CardLayout) (panelCards.getLayout());
		cardLayout.show(panelCards, STEP1);
	}

	private static void createGUISteps() {
		ImportForm that = new ImportForm();
		that.setVisible(true);
	}
	
	private void initComponents() {
		Container panelContent = this.getContentPane();
//		panelContent.setLayout(new FlowLayout());
		
		JPanel panelFooter = new JPanel();		
		Box boxFooter = new Box(BoxLayout.X_AXIS);
		
//		panelStep1 = new Step1(this);
		panelStep1 = new Step1();
		panelStep2 = new Step2();
		
//		cardLayout = new CardLayout(); 
//		panelStep1.setLayout(cardLayout);
		
		//Create the panel that contains the "cards".
		panelCards = new JPanel(new CardLayout());
		panelCards.add(panelStep1, STEP1);
		panelCards.add(panelStep2, STEP2);

	    
		btnBack = new JButton("< Back");
	    btnNext = new JButton("Next >");
	    btnCancel = new JButton("Cancel");
	    
	    btnBack.setEnabled(false);
	    
	    btnBack.addActionListener(this);
	    btnNext.addActionListener(this);
	    btnCancel.addActionListener(this);
	    
	    panelFooter.setLayout(new BorderLayout());
	    panelFooter.add(new JSeparator(), BorderLayout.NORTH);

	    boxFooter.setBorder(new EmptyBorder(new Insets(5, 10, 5, 10))); 
	    boxFooter.add(btnBack);
	    boxFooter.add(Box.createHorizontalStrut(10));
	    boxFooter.add(btnNext);
	    boxFooter.add(Box.createHorizontalStrut(30));
	    boxFooter.add(btnCancel);
	    
	    panelFooter.add(boxFooter, BorderLayout.EAST);
	    panelContent.add(panelFooter, BorderLayout.SOUTH);
	    panelContent.add(panelCards, BorderLayout.CENTER);
	    
	    
	}
	
	public void actionPerformed(ActionEvent e) {
		if (e.getSource() == btnNext) {
			System.out.println("next");
			cardLayout.next(panelCards);
			btnBack.setEnabled(true);
			btnNext.setEnabled(false);
//			cardLayout.show(panelCards, STEP1);
		} else if (e.getSource() == btnBack) {
			System.out.println("back");	
			cardLayout.previous(panelCards);
			btnNext.setEnabled(true);
			btnBack.setEnabled(false);
		} else if (e.getSource() == btnCancel) {
			//System.exit(0);
			this.setVisible(false);
		}
    }
	
	/**
	 * @param args
	 */
//	public static void main(String[] args) {
//		// TODO Auto-generated method stub
//		//Schedule a job for the event-dispatching thread:
//        //creating and showing this application's GUI.
//        javax.swing.SwingUtilities.invokeLater(new Runnable() {
//            public void run() {
////            	UIManager.put("swing.boldMetal", Boolean.FALSE);
//            	createGUISteps();
//            }
//        });
//	}

}
